<!DOCTYPE html>
<html lang="en">

<head>
  <meta charset="UTF-8">
  <meta http-equiv="X-UA-Compatible" content="IE=edge">
  <meta name="viewport" content="width=device-width, initial-scale=1.0">
  <title>自定义Promise</title>
  <script src="./Promise.js"></script>
</head>

<body>

</body>
<script>
  /* const p = new Promise((resolve, reject) => {
    setTimeout(() => {
      // resolve('ok')
      reject('error')
    }, 1000)
    // resolve('ok')
    // reject('error')
    // throw 'error'
  }) */

  /* const res = p.then((value) => {
    console.log(value);
    // return 'meiwenti'
    return new Promise((resolve,reject)=>{
      resolve('ok')
    })
    // throw '出错了'
  }, (reason) => {
    console.warn(reason)
    // throw 'er'
  }) */
  /* p.then((value) => {
    alert(value);
  }, (reson) => {
    alert(reson)
  }) */
  // console.log(res);
  /* let res = p.then()
  .then(resolve => {
    console.log(222);
  }).catch(reason => {
    console.warn(reason);
  })

  console.log(res); */

  /*   const p = Promise.resolve('ok')
    console.log(p); */

  /* const p = Promise.reject('error')
  console.log(p); */

  /* const p1 = new Promise((resolve, reject) => {
    resolve('ok')
  })
  const p2 = Promise.resolve('成功')
  const p4 = Promise.resolve('成功啦')
  // const p3 = Promise.reject('失败')

  const res = Promise.all([p1, p2, p4])
  console.log(res); */

  /* const p1 = new Promise((resolve, reject) => {
    resolve('ok')
  })
  const p2 = Promise.resolve('成功')
  const p4 = Promise.resolve('成功啦')
  // const p3 = Promise.reject('失败')

  const res = Promise.race([p1, p2, p4])
  console.log(res); */

  const p1 = new Promise((resolve,reject)=>{
    resolve('ok')
    console.log(111);
  })

  p1.then(v=>{
    console.log(222);
  },r=>{})

  console.log(333);
</script>

</html>